#pragma once

#include "qlib/all.h"
#include "../../render/components.hpp"
namespace qbe::editing::Extension {

struct ExtensionModel {
  bool inited = false;
  bool exitable = true;
  bool request_exit = false;
  bool key_space_switch_mode = true; //记录从当前模式按下空格
  std::vector<qlib::Vec2d> pick_line_points;//多选线工具
  std::vector<qlib::Path::s_ptr> adds; //新增结果
  std::vector<entt::entity> removes; //删除结果
  std::vector<bool> selected; //被选中结果
  //可视化
  qbe::render::LineMesh pick_line; //多选线
  qbe::render::PointMesh inter_points; //延申交点
  // std::vector<qbe::render::LineMesh> extend_lines; //延申的线
  qbe::render::LineListMesh extend_lines; //延申的线
  
  void updatePickLine(std::vector<qlib::Vec2d> points){
    pick_line = qbe::render::LineMesh(points);
  }

  void updateInterPoints(std::vector<qlib::Vec2d> points){
    inter_points = qbe::render::PointMesh(points);
  }

  void updateExtendLines(std::vector<std::vector<qlib::Vec2d>> list){
    extend_lines = qbe::render::LineListMesh(list);
  }

  void updateVisualData(std::vector<qlib::Vec2d> line, std::vector<qlib::Vec2d> points, std::vector<std::vector<qlib::Vec2d>> list){
    updatePickLine(line);
    updateInterPoints(points);
    updateExtendLines(list);
  }

  void clear(){
    inited = false;
    key_space_switch_mode = false;
    clear_visual_data();
  }

  void clear_visual_data(){
    pick_line_points.clear();
    updatePickLine({});
    updateInterPoints({});
    updateExtendLines({});
  }
};

}